{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Excel表格“BJweather\"收集了某城市的天气数据，基于“BJweatherxlsx”数据集回答以下问题，数据导入后命名为\n",
    "BJweather。以下每道题均是在原始数据基础上进行的，题干所涉及到的数据修改操作不继承到其他题中."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 101、(单选题) 请通过min()函数分析BJweather.xlsx，说出显示的“前天气温”列中的最小值是(C)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "# 读取数据\n",
    "df = pd.read_excel(\"BJweather_1678065761546.xlsx\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>日期</th>\n",
       "      <th>白天天气</th>\n",
       "      <th>白天气温</th>\n",
       "      <th>昨天气温</th>\n",
       "      <th>前天气温</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>2022-01-01</td>\n",
       "      <td>晴</td>\n",
       "      <td>-8</td>\n",
       "      <td>-7</td>\n",
       "      <td>-7</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>2022-01-02</td>\n",
       "      <td>多云</td>\n",
       "      <td>-7</td>\n",
       "      <td>-8</td>\n",
       "      <td>-7</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>2022-01-03</td>\n",
       "      <td>晴</td>\n",
       "      <td>-7</td>\n",
       "      <td>-7</td>\n",
       "      <td>-8</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>2022-01-04</td>\n",
       "      <td>晴</td>\n",
       "      <td>-6</td>\n",
       "      <td>-7</td>\n",
       "      <td>-7</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>2022-01-05</td>\n",
       "      <td>晴</td>\n",
       "      <td>-6</td>\n",
       "      <td>-6</td>\n",
       "      <td>-7</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "          日期 白天天气  白天气温  昨天气温  前天气温\n",
       "0 2022-01-01    晴    -8    -7    -7\n",
       "1 2022-01-02   多云    -7    -8    -7\n",
       "2 2022-01-03    晴    -7    -7    -8\n",
       "3 2022-01-04    晴    -6    -7    -7\n",
       "4 2022-01-05    晴    -6    -6    -7"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 简单查看一下前几行, 看有没有读取正确\n",
    "df.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "-12"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# “前天气温”列的最小值\n",
    "df[\"前天气温\"].min()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 102、下列正确导入数据集的语句是 (A)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 运行该函数的帮助文档\n",
    "pd.read_excel?"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>日期</th>\n",
       "      <th>白天天气</th>\n",
       "      <th>白天气温</th>\n",
       "      <th>昨天气温</th>\n",
       "      <th>前天气温</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>2022-01-01</td>\n",
       "      <td>晴</td>\n",
       "      <td>-8</td>\n",
       "      <td>-7</td>\n",
       "      <td>-7</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>2022-01-02</td>\n",
       "      <td>多云</td>\n",
       "      <td>-7</td>\n",
       "      <td>-8</td>\n",
       "      <td>-7</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>2022-01-03</td>\n",
       "      <td>晴</td>\n",
       "      <td>-7</td>\n",
       "      <td>-7</td>\n",
       "      <td>-8</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>2022-01-04</td>\n",
       "      <td>晴</td>\n",
       "      <td>-6</td>\n",
       "      <td>-7</td>\n",
       "      <td>-7</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>2022-01-05</td>\n",
       "      <td>晴</td>\n",
       "      <td>-6</td>\n",
       "      <td>-6</td>\n",
       "      <td>-7</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "          日期 白天天气  白天气温  昨天气温  前天气温\n",
       "0 2022-01-01    晴    -8    -7    -7\n",
       "1 2022-01-02   多云    -7    -8    -7\n",
       "2 2022-01-03    晴    -7    -7    -8\n",
       "3 2022-01-04    晴    -6    -7    -7\n",
       "4 2022-01-05    晴    -6    -6    -7"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df = pd.read_excel(\"BJweather_1678065761546.xlsx\", index_col=None)\n",
    "df.head()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 103、请使用shape方法，查看BJweather.xlsx数据表的行数为 (B)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(371, 5)"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.shape"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 104、对BJweather的白天气温中增量为2地选择索引100到200的元素，该部分数据的平均值为 (C)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "17.06"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df[\"白天气温\"].iloc[100:200:2].mean()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 105、请使用count()函数，求出BJweather中以'白天天气'为一组，'前天气温'里'阴'的数量为(A)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>日期</th>\n",
       "      <th>白天天气</th>\n",
       "      <th>白天气温</th>\n",
       "      <th>昨天气温</th>\n",
       "      <th>前天气温</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>2022-01-01</td>\n",
       "      <td>晴</td>\n",
       "      <td>-8</td>\n",
       "      <td>-7</td>\n",
       "      <td>-7</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>2022-01-02</td>\n",
       "      <td>多云</td>\n",
       "      <td>-7</td>\n",
       "      <td>-8</td>\n",
       "      <td>-7</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>2022-01-03</td>\n",
       "      <td>晴</td>\n",
       "      <td>-7</td>\n",
       "      <td>-7</td>\n",
       "      <td>-8</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>2022-01-04</td>\n",
       "      <td>晴</td>\n",
       "      <td>-6</td>\n",
       "      <td>-7</td>\n",
       "      <td>-7</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>2022-01-05</td>\n",
       "      <td>晴</td>\n",
       "      <td>-6</td>\n",
       "      <td>-6</td>\n",
       "      <td>-7</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>366</th>\n",
       "      <td>2022-12-27</td>\n",
       "      <td>晴</td>\n",
       "      <td>-8</td>\n",
       "      <td>-7</td>\n",
       "      <td>-7</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>367</th>\n",
       "      <td>2022-12-28</td>\n",
       "      <td>晴</td>\n",
       "      <td>-8</td>\n",
       "      <td>-8</td>\n",
       "      <td>-7</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>368</th>\n",
       "      <td>2022-12-29</td>\n",
       "      <td>晴</td>\n",
       "      <td>-9</td>\n",
       "      <td>-8</td>\n",
       "      <td>-8</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>369</th>\n",
       "      <td>2022-12-30</td>\n",
       "      <td>晴</td>\n",
       "      <td>-8</td>\n",
       "      <td>-9</td>\n",
       "      <td>-8</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>370</th>\n",
       "      <td>2022-12-31</td>\n",
       "      <td>晴</td>\n",
       "      <td>-7</td>\n",
       "      <td>-8</td>\n",
       "      <td>-9</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>371 rows × 5 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "            日期 白天天气  白天气温  昨天气温  前天气温\n",
       "0   2022-01-01    晴    -8    -7    -7\n",
       "1   2022-01-02   多云    -7    -8    -7\n",
       "2   2022-01-03    晴    -7    -7    -8\n",
       "3   2022-01-04    晴    -6    -7    -7\n",
       "4   2022-01-05    晴    -6    -6    -7\n",
       "..         ...  ...   ...   ...   ...\n",
       "366 2022-12-27    晴    -8    -7    -7\n",
       "367 2022-12-28    晴    -8    -8    -7\n",
       "368 2022-12-29    晴    -9    -8    -8\n",
       "369 2022-12-30    晴    -8    -9    -8\n",
       "370 2022-12-31    晴    -7    -8    -9\n",
       "\n",
       "[371 rows x 5 columns]"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "日期      20\n",
       "白天天气    20\n",
       "白天气温    20\n",
       "昨天气温    20\n",
       "前天气温    20\n",
       "dtype: int64"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "condition = (df[\"白天天气\"]==\"阴\")\n",
    "df[condition].count()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 106、用BJweather的最后一个日期减去第一个日期得到的天数为(B)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 将字符串格式转化为pandas日期格式\n",
    "df[\"日期\"] = pd.to_datetime(df[\"日期\"])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Timedelta('364 days 00:00:00')"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df[\"日期\"].iloc[-1] - df[\"日期\"].iloc[0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.12"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
